// pages/author/author.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    token: null
  },
  go_back() {
    console.log("dianji1le1")
    wx.reLaunch({
      url: '../recruit/index/index',
    })
  },
  getuserinfo: function(e) {
    const encryptedData = e.detail.encryptedData;
    const iv = e.detail.iv;
    if (e.detail.userInfo) {
      wx.login({
        success: function(res) {
          // console.log(res)
          const code = res.code;
          // console.log(code)
          wx.request({
            method: 'POST',
            url: app.globalData.url + '/api/sign/login/getWxLogin',
            data: {
              code: code,
              encryptedData: encryptedData,
              iv: iv
            },
            success: function(e) {
              // console.log(e)
              const getuserinfo = JSON.parse(e.data.data.getuserinfo)
              // console.log(getuserinfo)
              const openId = getuserinfo.openId;
              const unionId = getuserinfo.unionId;
              app.globalData.openId = openId;
              app.globalData.unionId = unionId;
              wx.setStorageSync('openId', openId)
              wx.setStorageSync('unionId', unionId)

              var _token = wx.getStorageSync('token');
              if (openId) {
                if (_token) {

                  var _role = wx.getStorageSync('reg_register_role');

                  app.register_info.register_role = _role;
                  app.globalData.token = _token;

                  wx.navigateBack({
                    delta: 1,
                  })

                  // wx.switchTab({ //   这里变化
                  //   url: '../index/index'
                  // })
                } else {
                  wx.redirectTo({
                    url: '../login/login'
                  })
                }
              } else {
                console.log("无openId")
              }


            }
          })
        }
      })
    } else {
      // console.log('执行到这里，说明拒绝了授权')
      wx.showToast({
        title: "小主~为了您更好的体验~请先同意授权~",
        icon: 'none',
        duration: 3000
      });
    }

  },
  onLoad: function() {

  }
})